package cmpe451.group7.ourcity.beans;

import java.io.Serializable;
import java.util.LinkedList;
import java.util.List;

import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;

import cmpe451.group7.ourcity.entity.Place;
import cmpe451.group7.ourcity.entity.Tag;
import cmpe451.group7.ourcity.recommendation.FreebaseQuery;
import cmpe451.group7.ourcity.service.SearchService;

/**
 * This is a test bean used to test the similarity findings of the search
 * results
 */
@ManagedBean
@ViewScoped
public class TagBean implements Serializable {

	private static final long serialVersionUID = -3106395871039054455L;

	@ManagedProperty(value = "#{searchService}")
	private SearchService searchService;

	private List<Tag> selectedTags = new LinkedList<Tag>();

	private List<Tag> similarTags;
	private List<Place> similarPlaces;

	public void search() {
		similarTags = searchService.getRelatedTags(selectedTags);
		similarPlaces = searchService.getRelatedPlaces(selectedTags);
	}

	public List<Tag> completeTags(String query) {
		return FreebaseQuery.completeTags(query);
	}

	/* ### getters & setters ##################### */

	public void addMessage(FacesMessage message) {
		FacesContext.getCurrentInstance().addMessage(null, message);
	}

	public List<Tag> getSelectedTags() {
		return selectedTags;
	}

	public void setSelectedTags(List<Tag> selectedTags) {
		this.selectedTags = selectedTags;
	}

	public List<Tag> getSimilarTags() {
		return similarTags;
	}

	public void setSimilarTags(List<Tag> similarTags) {
		this.similarTags = similarTags;
	}

	public SearchService getSearchService() {
		return searchService;
	}

	public void setSearchService(SearchService searchService) {
		this.searchService = searchService;
	}

	public List<Place> getSimilarPlaces() {
		return similarPlaces;
	}

	public void setSimilarPlaces(List<Place> similarPlaces) {
		this.similarPlaces = similarPlaces;
	}

}